package com.wwfish.cms.service;

import com.nexustar.gwt.widgets.client.model.PaginationModelDto;
import com.wwfish.cms.model.CMSConstants;
import com.wwfish.cms.model.GeneralCodeDto;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2010-8-9
 * Time: 9:59:06
 * To change this template use File | Settings | File Templates.
 */
public class CodeManagerImpl implements CodeManager {
    public List<GeneralCodeDto> getCodesByParentId(Long parentId) {
        List r = new ArrayList();
        mockCode(r, parentId);
        if (r.size() > 0) return r;
        for (int i = 0; i < (int) (Math.random() * 10); i++) {
            GeneralCodeDto dto = new GeneralCodeDto(new Long(i), parentId + "代码" + i, (parentId + i + ""));
            r.add(dto);
        }
        return r;
    }

    private List mockCode(List r, Long parentId) {
        if(parentId == null){
            r.add(new GeneralCodeDto(100l, "审核状态", "100"));
            r.add(new GeneralCodeDto(200l, "城市类型", "200"));
            r.add(new GeneralCodeDto(300l, "图片类型", "300"));
            r.add(new GeneralCodeDto(400l, "人员类型", "400"));
            return r;
        }
        if (parentId.equals(CMSConstants._CODE_RESOURCE_VARIETY_ID)) {
            r.add(new GeneralCodeDto(0l, "图片", "0"));
            r.add(new GeneralCodeDto(1l, "音乐", "1"));
            r.add(new GeneralCodeDto(2l, "视频", "2"));
            r.add(new GeneralCodeDto(3l, "Flash", "3"));
            return r;
        } else if (parentId.equals(CMSConstants._CODE_CONTENT_WORKFLOW_STATUS_ID)) {
            r.add(new GeneralCodeDto(0l, "草稿", "0"));
            r.add(new GeneralCodeDto(1l, "未审核", "1"));
            r.add(new GeneralCodeDto(2l, "通过", "2"));
            r.add(new GeneralCodeDto(3l, "拒绝", "3"));
        }

        return r;
    }


    public void saveAndUpdate(GeneralCodeDto dto) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void delete(GeneralCodeDto dto) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public PaginationModelDto<GeneralCodeDto> getPageEntities(Integer begin, Integer count, Map<String, String> conditions) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }
}
